package comxin.demo3;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ConstructMethoddemo1 {
    @Test
    public void method1() throws ClassNotFoundException, NoSuchMethodException {
        Class<?> aClass = Class.forName("comxin.Student");
        Constructor<?>[] constructor = aClass.getConstructors();
        for (Constructor constructor1:constructor){
            System.out.println(constructor1);
        }
    }
    @Test
    public void method2() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("comxin.Student");
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor constructor:declaredConstructors){
            System.out.println(constructor);
        }

    }
    @Test
    public void method3() throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("comxin.Student");
        Constructor<?> constructor = aClass.getConstructor( Integer.class, String.class,int.class);
        Object o = constructor.newInstance(1,"1",1);
        System.out.println(o);
    }
}
